/*******************************************************************************
 * Copyright:   Copyright (c) 2007. Hisilicon Technologies, CO., LTD.
 * Version:     V300R001B01
 * Filename:    keypad.h
 * Description: This module is head file of keypad information
 * History:
                1.Created by SunShaojie on 2007/08/31
*******************************************************************************/

#ifndef __KEYPAD_HPP__
#define __KEYPAD_HPP__

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------

#define SC_KEY_BIT_NUMS             64
#define VK_KEY_BIT_NUMS             256
#define DWORD_BIT_NUMS              32

#define SC_KEY_NUMS             (SC_KEY_BIT_NUMS/DWORD_BIT_NUMS)
#define VK_KEY_NUMS             (VK_KEY_BIT_NUMS/DWORD_BIT_NUMS)

extern UINT8 g_ucScToVkTable[];

// restore keypad intrrupt mask status
typedef struct
{
    UINT32  aShortKey[SC_KEY_NUMS];         // key short press mask
    UINT32  aDialKey[SC_KEY_NUMS];          // key Dialing mask
}KEYPAD_INTR_MASK, *PKEYPAD_INTR_MASK;

// Dial unmask key
typedef struct {
    UINT8  ucVk;
    BOOL   bIsWakeOn;
}KEYPAD_DIAL_WAKEUP, *PKEYPAD_DIAL_WAKEUP;

// dial unmask
typedef struct {
    UINT8  ucCount;
    KEYPAD_DIAL_WAKEUP  *pItem;
}KEYPAD_DIAL_UNMASK, *PKEYPAD_DIAL_UNMASK;

extern KEYPAD_DIAL_UNMASK g_KpdUnmask;
//------------------------------------------------------------------------------

typedef struct {
    UINT8  ucVk;                  // virtual key to be result of remapping
    UINT8  ucKeyNum;              // number of keys to map
    UINT16 ucDelay;               // debounce delay in ms
    UINT8  *pVKeys;               // virtual keys to map from
} KEYPAD_REMAP_ITEM, *PKEYPAD_REMAP_ITEM;

typedef struct {
    UINT16 usCount;
    KEYPAD_REMAP_ITEM *pItem;
} KEYPAD_REMAP;

extern KEYPAD_REMAP g_sKpdLngRmp;

//------------------------------------------------------------------------------

typedef struct {
    UINT8  ucCount;               // number of keys
    UINT8  *pVKey;                // virtual keys (in order) for this key event
} KEYPAD_MULTI_KEYS,*PKEYPAD_MULTI_KEYS;

typedef struct {
    UINT8  ucVk;                  // virtual key to be multiplied
    KEYPAD_MULTI_KEYS *pDownKeys; // virtual keys for down event
    KEYPAD_MULTI_KEYS *pUpKeys;   // virtual keys for up event
} KEYPAD_MULTI_ITEM, *PKEYPAD_MULTI_ITEM;

typedef struct {
    UINT16 usCount;
    KEYPAD_MULTI_ITEM *pItem;
} KEYPAD_MULTI, *PKEYPAD_MULTI;

extern KEYPAD_MULTI g_sKpdMulti;

//------------------------------------------------------------------------------

typedef struct {
    UINT16 usCount;               // number of keys to block repeat
    UINT8  *pVKey;                // virtual keys blocking repeat
} KEYPAD_REPEAT_BLOCK, *PKEYPAD_REPEAT_BLOCK;

typedef struct {
    UINT8  ucVk;                  // virtual key to be repeated
    BOOL   bSilent;               // repeat should be without key click
    KEYPAD_MULTI_KEYS *pMultiKeys;//
    KEYPAD_REPEAT_BLOCK *pBlock;  // virtual keys blocking repeat
} KEYPAD_REPEAT_ITEM, *PKEYPAD_REPEAT_ITEM;

typedef struct {
    UINT16 usCount;
    KEYPAD_REPEAT_ITEM *pItem;
} KEYPAD_REPEAT, *PKEYPAD_REPEAT;

extern KEYPAD_REPEAT g_sKpdRpt;

//------------------------------------------------------------------------------

typedef struct {
    UINT16 usCount;
    UINT8 *pItem;
} KEYPAD_SILENT, *PKEYPAD_SILENT;

extern KEYPAD_SILENT g_sKpdSlnt;

//------------------------------------------------------------------------------

#define KEY_ARRAY_SET_BIT(array, bit)     array[(bit) >> 5] |= 1 << ((bit) & 0x1F)
#define KEY_ARRAY_CLR_BIT(array, bit)     array[(bit) >> 5] &= ~(1 << ((bit) & 0x1F))
#define KEY_ARRAY_BIT_IS_SET(array, bit)  (array[(bit) >> 5] & (1 << ((bit) & 0x1F)))

typedef struct {
    BOOL bPending;
    BOOL bRemapped;
    DWORD dwTime;
    DWORD dwState;
} KEYPAD_REMAP_STATE, *PKEYPAD_REMAP_STATE;

typedef struct {
    BOOL bPending;
    DWORD dwTime;
    BOOL bBlocked;
} KEYPAD_REPEAT_STATE, *PKEYPAD_REPEAT_STATE;

//------------------------------------------------------------------------------

// the keypad state when system PowerUp

typedef struct {
    DWORD adwVkState[VK_KEY_NUMS];          // Key pressed states
    DWORD dwScanMode;                       // Scan key mode
    BOOL  bKeyPressed;                      // There are key pressed
    BOOL  bKeyWakeUp;                       // There are wakeup key pressed
} POWERUP_KEYPAD_STATE, *PPOWERUP_KEYPAD_STATE;


// Set debug zone names for the driver.
#ifdef DEBUG
#if 0
#define ZONE_ERROR          DEBUGZONE(0)
#define ZONE_WARN           DEBUGZONE(1)
#define ZONE_FUNCTION       DEBUGZONE(2)
#define ZONE_INIT           DEBUGZONE(3)
#define ZONE_INFO           DEBUGZONE(4)
#define ZONE_IST            DEBUGZONE(5)
#define ZONE_KEYEVENT       DEBUGZONE(6)
#define ZONE_REMAP          DEBUGZONE(7)
#define ZONE_REPEAT         DEBUGZONE(8)
#define ZONE_IOCTL          DEBUGZONE(9)
#define ZONE_CNTL           DEBUGZONE(10)
#define ZONE_BKL            DEBUGZONE(11)
#define ZONE_PDD            DEBUGZONE(12)
#endif

#define ZONE_ERROR          (1)
#define ZONE_WARN           (0)
#define ZONE_FUNCTION       (0)
#define ZONE_INIT           (0)
#define ZONE_INFO           (0)
#define ZONE_IST            (0)
#define ZONE_KEYEVENT       (0)
#define ZONE_REMAP          (0)
#define ZONE_REPEAT         (0)
#define ZONE_IOCTL          (0)
#define ZONE_CNTL           (0)
#define ZONE_BKL            (0)
#define ZONE_PDD            (0)

#endif // DEBUG

//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------


//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------

// Initialize IOCMG
BOOL InitIocmgRegister(VOID);

// Initialize the PDD
PVOID KpdPddInit(VOID);

// Deinitialize the PDD. pddContext is the value returned from KpdPddInit.
VOID KpdPddDeinit(VOID);



//------------------------------------------------------------------------------

#ifdef __cplusplus
}
#endif

#endif
